package com.qf.service;

import com.qf.dao.AccountDao;
import com.qf.pojo.Account;

import java.util.List;

public class AccountServiceImpl implements AccountService{

    AccountDao accountDao;

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    @Override
    public void transfer(String fromName, String toName, double money) {
        Account fromAccount = accountDao.selectByName(fromName);
        Account toAccount = accountDao.selectByName(toName);

        //更新余额
        fromAccount.setMoney(fromAccount.getMoney() - money);
        toAccount.setMoney(toAccount.getMoney() + money);

        //更新数据库
        accountDao.update(fromAccount);
        //System.out.println(1/0);
        accountDao.update(toAccount);
    }
}
